import request from '@/util/axios';
import type { getUrlRequest, uploadRequest } from './type';
// 统一管理接口
enum API {
  GET_URL = '/api/compliance_registration/asset_compliance/file/upload', // 资产合规文件上传
  UPLOAD = '/api/compliance_registration/asset_compliance/file/merge', // 资产合规文件合并
  GET_URL_REG = '/api/asset_registration/file/upload', // 登记上传
  UPLOAD_REG = '/api/asset_registration/file/merge', // 合并
  GET_URL_EVA = '/api/data_evaluation/file/upload', 
  UPLOAD_EVA = '/api/data_evaluation/file/merge',
  RUBIAO_UPLOAD = '/api/cost_aggregation/asset_rubiao/file/upload', // 确认入表文件上传
  RUBIAO_MEGRE = '/api/cost_aggregation/asset_rubiao/file/merge', // 确认入表文件合并
  DECREASE_UPLOAD = '/api/metrological/decrease/file/upload', //资产减值文件上传
  DECREASE_MERGE = '/api/metrological/decrease/file/merge', //       

  Download = '/api/file/download', // 下载文件
  Merge = '/api/file/merge', // 合并文件
  ChunkUpload = '/api/file/chunk_upload', // 分片上传
  Prepare = '/api/file/prepare', // 分片上传准备
}

/**
 * @method 根据类型获取对应模块的上传的URL
 */
export function uplodUrl_post(data:getUrlRequest){
  switch (data.type) {
    case 'compliance':
      return request.post(API.GET_URL,data)
    case 'registration': 
      return request.post(API.GET_URL_REG,data)
    case 'evaluation': 
      return request.post(API.GET_URL_EVA,data)
    case 'enterTable':
      return request.post(API.RUBIAO_UPLOAD,data)
    case 'decrease':
      return request.post(API.DECREASE_UPLOAD,data)  
    default:
      break;
  }
  return Promise.reject(new Error(`${data.type}参数不正确`))
}

/**
 * @method 循环上传文件
 */
export function loopUploadFile(url: string, data: any, fileType:string){
  return request.put(url,data,fileType)
}

/**
 * @method 根据类型获取对应模块的合并
 */
export function mergeUploadFile_post(data:uploadRequest){
  
  switch (data.type) {
    case 'compliance':
      return request.post(API.UPLOAD,data)
    case 'registration': 
      return request.post(API.UPLOAD_REG,data)
    case 'evaluation': 
      return request.post(API.UPLOAD_EVA,data)
    case 'enterTable':
      return request.post(API.RUBIAO_MEGRE,data)
    case 'decrease':
      return request.post(API.DECREASE_MERGE,data)    
    default:
      break;
  }
  return Promise.reject(new Error(`${data.type}参数不正确`))
}


